package com.company.L_5_1;

import java.lang.reflect.Method;

/**
 * Created by vilen on 2015/3/30.
 * 方法的反射  方法的名称 和方法的参数列表
 * invoke（对象，参数列表）
 */
public class L_5_1 {
    public static void main(String[] args) {
        //获取 int int
        try {
            Class a = Class.forName("com.company.L_5_1.A");
            A a1 =(A)a.newInstance();
            //获取public 方法
            //getDeclaredMethods() 自己声明的方法
            Method m = a.getMethod("print", new Class[]{int.class, int.class});
            //方法的反射
            m.invoke(a1,new Object[]{10,20});

            System.out.println("=======================");
            Method m1 = a.getMethod("print",new Class[]{String.class,String.class});
            m1.invoke(a1,new Object[]{"nihao","NIHao2"});

            System.out.println("=================================");
            Method m2 = a.getMethod("print");
            m2.invoke(a1);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
class A{
    public void print(){
        System.out.println("Hello world");
    }
        public void print(int a, int b){
            System.out.println(a+b);
        }
    public void print(String a, String b){
        System.out.println(a.toUpperCase()+","+ b.toLowerCase());
    }
}
